
$(function () {
  //获取拼接在url后的视频的输入值
var str = location.search;
var params=new URLSearchParams(str);
var word=params.get('word');

$('.detailsearch input').val(word)
  //触发搜索函数
  search()
  function search() {
   /*在video表中查找相关番剧*/
      $('.search-anime-content').empty()
      $('.likecontent').empty()
      let searchcontent = $('.detailsearch input').val()
      axios({
        url: 'static/searchvideo',
        method: 'GET',
        params:{
          word:searchcontent
        }
      }).then(function (res) {
        let data = res.data.data
        if(data.length==0){

          return
        }
        if (data.length != 0) {
          $(res.data.data).each(function (index, ele) {
            $('.search-anime-content').append(`
              <div class="animeintro clearfix">
              <a href="./animedetail.html?vid=${ele.videoId}" target="_blank" rel="opener">
              <img src="${ele.videoUrl}" alt="">
              </a>
              <div class="introcontent">
                <h3>${ele.videoTitle}</h3>
                <p>${ele.videoMold}</p>
                <span>${ele.videoIntro}
                </span>
                <div class="score">
                  <p>${ele.score}<span>分</span></p>
                </div>
              </div>
              </div>`)
          })
        } else {
          $('.search-anime-content').html('暂无相关番剧')
        }
        history.pushState({},'',`http://localhost:8080/mikufun/search.html?word=${searchcontent}`)
        
      })
      /*在detail表中查找相关的用户视频*/
      axios({
        url: 'selectdetailbyname',
        method: 'GET',
        params: {
          word: searchcontent
        }
      }).then(function (res) {
        if(res.data.data.length!=0){
        $(res.data.data).each(function (index, ele) {
          $('.likecontent').append(`
                  <div class="likebox">
                    <a href="./uservideodetail.html?vid=${ele.videoUid}" target="_blank" rel="opener">
                      <img src="${ele.detailImg}" alt="">
                      <p>${ele.detailTitle}</p>
                      <span>${ele.username}</span>
                       <span>${ele.videoTime}</span>
                    </a>
                  </div>
                `)
          })
        }else{
          $('.likecontent').html('暂无相关视频')
        }
        history.pushState({},'',`http://localhost:8080/mikufun/search.html?word=${searchcontent}`)
      })
  }
  $('.detailsearch button').click(function () {
    search()
  })

})



